package com.higgins.client.agentapp.components;

import java.util.List;
import java.util.logging.Logger;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.higgins.client.GreetingService;
import com.higgins.client.GreetingServiceAsync;
import com.higgins.client.agentapp.datamodel.AgencyDTO;
import com.higgins.client.agentapp.interfaces.AgencyListListener;
import com.higgins.client.agentapp.service.AgentAppService;
import com.higgins.client.agentapp.service.AgentAppServiceAsync;
import com.higgins.client.dataModel.CoveringLetterDTO;
import com.higgins.client.generic.components.GenericColumn;

public class AgencyColumn extends GenericColumn		{
	private static final Logger log = Logger.getLogger(AgencyColumn.class.getName());
	private final AgentAppServiceAsync agentAppService = GWT
			.create(AgentAppService.class);
	private AgencyListListener listener;

	public void addAgencyListListener(AgencyListListener listener)	{
		this.listener = listener;
	}
	
	public void loadList()	{
		retrieveCoveringLetterDTOs();
		
	}
	private void retrieveCoveringLetterDTOs()	{
		try {
			agentAppService.retrieveAgencys(new AsyncCallback<List<AgencyDTO>>()	{
					@Override
					public void onFailure(Throwable caught) {
						log.info("StrategyColumns: " + caught.toString());
					}

					@Override
					public void onSuccess(List<AgencyDTO> result) {
//						List<String> list = new ArrayList<String>();
//						for (CoveringLetterDTO coveringLetterDTO:result)	{
//							list.add(coveringLetterDTO.getName());
//						}
						setList(result);
						listener.setAgencyListLoaded(true);
					}
				});
		} catch (IllegalArgumentException e) {
			log.info("StrategyColumns: " + e.toString());
		}	}		
}
